package com.uzhie.web.module;

import com.uzhie.exception.WarningException;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.*;


/**
 * 报警模块
 * create by lilongfei
 */
@Table(name="mjm_warning_collect")
public class WarningCollect implements Serializable,Cloneable{
    /** 警情id */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotEmpty(message = WarningException.Status.ID_ISNULL)
    private String id ;
    /** 警情编码 */
    private String code ;
    /** 部门ID */
    @NotEmpty(message = WarningException.Status.DEPART_ERROR)
    private String departId ;
    /** 部门名称 */
    @NotEmpty(message = WarningException.Status.DEPART_ERROR)
    private String departName ;
    /** 车牌号 */
    private String vehicleNumber ;
    /**
     * 报警类别
     */
    private String category;
    /**
     * 内置sim卡
     */
    @NotEmpty(message = WarningException.Status.SIM_ERROR)
    private String simNumber;
    /** 车辆类型 */
    private String vehicleType ;
    /** 当前速度 */
    private String speed ;
    /** 定位时间 */
    private String positionTime ;
    /** 行停时长 */
    private Double positionDuration ;
    /** 联系电话 */
    private String telephone ;
    /** 驾驶员 */
    private String driver ;
    /** 报警类型 */
    private String type ;
    /** 上报时间 */
    private Date startTime ;
    private Date endTime;
    /** （经度） */
    private Double lon ;
    /** （纬度） */
    private Double lat ;
    /** 位置信息 */
    private String address ;
    /** 警情状态 */
    // 0 删除 1 未处理 2 已处理 3 误报 4 忽略
    private Integer status ;
    /** 备注 */
    private String remark ;
    /** 处理人id */
    private String handlerId ;
    /** 处理人姓名 */
    private String handlerName ;
    /** 处理时间 */
    private Date handlerTime ;
    /**报警总条数**/
    private Integer count;

    /** 警情id */
    public String getId(){
        return this.id;
    }
    /** 警情id */
    public void setId(String id){
        this.id = id;
    }
    /** 警情编码 */
    public String getCode(){
        return this.code;
    }
    /** 警情编码 */
    public void setCode(String code){
        this.code = code;
    }
    /** 部门ID */
    public String getDepartId(){
        return this.departId;
    }
    /** 部门ID */
    public void setDepartId(String departId){
        this.departId = departId;
    }
    /** 部门名称 */
    public String getDepartName(){
        return this.departName;
    }
    /** 部门名称 */
    public void setDepartName(String departName){
        this.departName = departName;
    }
    /** 车牌号 */
    public String getVehicleNumber(){
        return this.vehicleNumber;
    }
    /** 车牌号 */
    public void setVehicleNumber(String vehicleNumber){
        this.vehicleNumber = vehicleNumber;
    }
    /** 车辆类型 */
    public String getVehicleType(){
        return this.vehicleType;
    }
    /** 车辆类型 */
    public void setVehicleType(String vehicleType){
        this.vehicleType = vehicleType;
    }
    /** 当前速度 */
    public String getSpeed(){
        return this.speed;
    }
    /** 当前速度 */
    public void setSpeed(String speed){
        this.speed = speed;
    }
    /** 定位时间 */
    public String getPositionTime(){
        return this.positionTime;
    }
    /** 定位时间 */
    public void setPositionTime(String positionTime){
        this.positionTime = positionTime;
    }
    /** 行停时长 */
    public Double getPositionDuration(){
        return this.positionDuration;
    }
    /** 行停时长 */
    public void setPositionDuration(Double positionDuration){
        this.positionDuration = positionDuration;
    }
    /** 联系电话 */
    public String getTelephone(){
        return this.telephone;
    }
    /** 联系电话 */
    public void setTelephone(String telephone){
        this.telephone = telephone;
    }
    /** 驾驶员 */
    public String getDriver(){
        return this.driver;
    }
    /** 驾驶员 */
    public void setDriver(String driver){
        this.driver = driver;
    }
    /** 报警类型 */
    public String getType(){
        return this.type;
    }
    /** 报警类型 */
    public void setType(String type){
        this.type = type;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Double getLon() {
        return lon;
    }

    public void setLon(Double lon) {
        this.lon = lon;
    }

    public Double getLat() {
        return lat;
    }

    public void setLat(Double lat) {
        this.lat = lat;
    }

    /** 位置信息 */
    public String getAddress(){
        return this.address;
    }
    /** 位置信息 */
    public void setAddress(String address){
        this.address = address;
    }
    /** 警情状态 */
    public Integer getStatus(){
        return this.status;
    }
    /** 警情状态 */
    public void setStatus(Integer status){
        this.status = status;
    }
    /** 备注 */
    public String getRemark(){
        return this.remark;
    }
    /** 备注 */
    public void setRemark(String remark){
        this.remark = remark;
    }
    /** 处理人id */
    public String getHandlerId(){
        return this.handlerId;
    }
    /** 处理人id */
    public void setHandlerId(String handlerId){
        this.handlerId = handlerId;
    }
    /** 处理人姓名 */
    public String getHandlerName(){
        return this.handlerName;
    }
    /** 处理人姓名 */
    public void setHandlerName(String handlerName){
        this.handlerName = handlerName;
    }
    /** 处理时间 */
    public Date getHandlerTime(){
        return this.handlerTime;
    }
    /** 处理时间 */
    public void setHandlerTime(Date handlerTime){
        this.handlerTime = handlerTime;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getSimNumber() {
        return simNumber;
    }

    public void setSimNumber(String simNumber) {
        this.simNumber = simNumber;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public static WarningCollect ReadFromOrder(List<Warning> orders){
        WarningCollect collect = new WarningCollect();
        collect.setId(UUID.randomUUID().toString().replace("-","").trim());
        collect.setAddress(orders.get(0).getAddress());
        collect.setCategory(orders.get(0).getCategory());
        collect.setCode(collect.getId());
        collect.setDepartId(orders.get(0).getDepartId());
        collect.setDriver(orders.get(0).getDriver());
        collect.setDepartName(orders.get(0).getDepartName());
        collect.setLat(orders.get(orders.size()-1).getLat());
        collect.setLon(orders.get(orders.size()-1).getLon());
        collect.setPositionDuration(orders.get(0).getPositionDuration());
        collect.setPositionTime(orders.get(0).getPositionTime());
        collect.setRemark(orders.get(0).getRemark());
        collect.setSimNumber(orders.get(0).getSimNumber());
        collect.setSpeed(orders.get(0).getSpeed());
        collect.setStatus(orders.get(0).getStatus());
        collect.setTelephone(orders.get(0).getTelephone());
        collect.setType(orders.get(0).getType());
        collect.setVehicleNumber(orders.get(0).getVehicleNumber());
        collect.setVehicleType(orders.get(0).getVehicleType());
        collect.setCount(orders.size());
        Warning begin = orders.get(0);
        if (orders.size()>1){
            Warning end = orders.get(orders.size()-1);
            collect.setStartTime(begin.getReportTime());
            collect.setEndTime(end.getReportTime());
        }else {
            collect.setStartTime(begin.getReportTime());
            collect.setEndTime(begin.getReportTime());
        }

        return collect;
    }
}